package jdbc;

import jdbc.utill.DButil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class JdbcDemo12 {
    public static void main(String[] args) throws Exception {
        // 王克晶带的班级信息
        /*
        teacher    class
        teacher_id = id
        select t.name,t.salary,c.name,c.floor
         from teacher t , class c where t.id=c.teacher_id
         */
        Connection connection = DButil.getConnection();
        String sql ="select t.name,t.salary,c.name,c.floor  " +
                "    from teacher t , class c where t.id=c.teacher_id " +
                " and t.name=?";
        PreparedStatement ps = connection.prepareStatement(sql);
        ps.setString(1,"王克晶");
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
           /* String tname = rs.getString("t.name");
            String tsalary = rs.getString("t.salary");
            String cname = rs.getString("c.name");
            String cfloor = rs.getString("c.floor");*/
            String tname = rs.getString(1);
            String tsalary = rs.getString(2);
            String cname = rs.getString(3);
            String cfloor = rs.getString(4);
            System.out.println(tname + "-- " + tsalary + "-- " + cname + "-- " + cfloor);
        }
        DButil.close(connection);
    }
}
